/**
*      author: Y_Yao
*      created: 2025-04-16 10:41:21
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
int n,m,k;
const int N = 2e5 + 7;
int a[N];

void solve()
{
    cin >> n >> m >> k;
    for(int i = 1;i <= k;i++)
    {
        a[i] = i;
    }

    if(m % k != 0)//正
    {
        int cnt = 0;
        for(int i = 1;i <= n * m;i++)
        {
            cout << a[cnt + 1] << " ";
            cnt = (cnt + 1) % (k);
            if(i % m == 0) cout << endl;
        }
    }
    else//反
    {
        int cnt = 1;
        for(int i = 1;i <= n;i++)
        {
            int cnt1 = cnt;
            for(int j = 1;j <= m;j++)
            {
                cout << a[cnt1] << " ";
                cnt1++;
                if(cnt1 == k + 1) cnt1 = 1;
            }
            cnt++;
            if(cnt == k + 1) cnt = 1;
            cout << endl;
        }
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}